package DesignPattern.Behavior.Observer;

import java.util.ArrayList;
import java.util.List;

public class SubscripitionSubject implements Subject {

    private List<Observer> weiXinUserList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weiXinUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weiXinUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : weiXinUserList) {
            // 调用观察者对象的update
            observer.update(message);
        }
    }
}
